//
//  main.cpp
//  circleList
//
//  Created by mxc on 15/12/23.
//  Copyright © 2015年 x_mitsui. All rights reserved.
//

#include <iostream>

class Node{
public:
    int Data;
    Node*pNext;
};

Node* create(int num){
    if (num==0) {
        return nullptr;
    }
    
    auto pHead = new Node;
    pHead->pNext=nullptr;
    auto p = pHead;
    for (int i =1; i<=num; i++) {
        auto pN      =   new Node;
        pN->Data     =   i;
        p->pNext     =   pN;
        p=pN;
    }
    p->pNext=pHead->pNext;
    delete pHead;
    return p->pNext;
}


int main(int argc, const char * argv[]) {
    int max = 20;
    auto pNode = create(max);
    auto p = pNode;
        for (int i=1; i<=max; i++) {
            std::cout<<p->Data<<" ";
            p=p->pNext;
        }
    
    std::cout << "输入起始数字。。。。";
    int startNum = 0;
    std::cin>>startNum;
    int ttt=1;
    while (p->pNext!=p) {
        ttt++;
        max-=1;
        std::cout<<"->"<<std::endl;
        int s=0;
        for (int in=1; in<=startNum-1; in++) {
//            std::cout <<"*:"<<in<<std::endl;
//            if (in==1) {std::cout<<"haha"<<std::endl;}
            if (in==startNum-1) {
                s=p->pNext->Data;
                std::cout << "消失的数字。。。。"<<startNum<<std::endl;
                auto q = p->pNext;
                p->pNext=q->pNext;
                delete q;
                
            }
            
            p=p->pNext;
            
        }
        startNum=s;
        
        
    }
    std::cout<<ttt<<"\\ ";
            for (int i=1; i<=max; i++) {
                std::cout<<p->Data<<" ";
                p=p->pNext;
            }
    
    //1,14,
    return 0;
}
